'''
     data from Percival & Walden

     SIMULATED AR(4) TIME SERIES (LOWER PLOT OF FIGURE 45)
     SOURCE: APPLIED PHYSICS LABORATORY (DON PERCIVAL)
     DELTA T: 1
     SAMPLE SIZE: 1024
'''

import sys
import pymutt
import matplotlib.pyplot as mpl
import numpy as np
from utilities import mtanalyze


dt = 1.00
dtunits = ""
data = [
	-41.461235,
	-28.159039,
	2.5902977,
	34.584435,
	50.221138,
	40.735588,
	8.58525,
	-31.276932,
	-59.135273,
	-60.68801,
	-33.799763,
	10.264538,
	49.92651,
	65.011215,
	47.90284,
	7.2169766,
	-36.405144,
	-59.76346,
	-50.53176,
	-13.955139,
	28.871962,
	54.370995,
	50.5273,
	22.02402,
	-14.396032,
	-40.946465,
	-44.290325,
	-25.033207,
	3.3495843,
	25.047705,
	31.806166,
	25.39833,
	11.916734,
	-2.7726126,
	-14.39522,
	-21.095484,
	-21.282593,
	-14.69849,
	-3.8348746,
	8.368739,
	16.816616,
	17.994923,
	11.721197,
	-0.3264284,
	-13.448496,
	-20.950054,
	-16.037777,
	-0.3230597,
	18.087236,
	27.888525,
	22.24638,
	3.6348643,
	-16.015463,
	-24.865238,
	-16.498152,
	3.4601092,
	20.956219,
	24.972324,
	13.113896,
	-4.1922708,
	-13.943526,
	-10.995645,
	0.6450442,
	10.97207,
	12.100036,
	3.7675145,
	-5.685991,
	-7.390485,
	0.25733632,
	9.718021,
	10.44514,
	1.6971262,
	-9.496649,
	-16.11132,
	-12.530828,
	0.71975416,
	16.409676,
	22.995937,
	13.985543,
	-4.96041,
	-21.479292,
	-26.30086,
	-16.250036,
	3.1651943,
	20.317984,
	25.748156,
	17.724619,
	0.41088974,
	-16.498756,
	-25.260866,
	-22.066057,
	-8.460947,
	9.387791,
	25.308872,
	33.412537,
	28.058493,
	8.471025,
	-18.84122,
	-41.680275,
	-47.63706,
	-29.874252,
	5.504405,
	41.03486,
	58.792854,
	47.464165,
	10.419853,
	-33.366013,
	-61.930218,
	-58.78773,
	-24.775959,
	21.676008,
	54.955227,
	57.393024,
	29.397306,
	-11.227726,
	-41.99718,
	-47.67176,
	-28.46036,
	4.083643,
	30.503456,
	36.39116,
	20.09366,
	-7.7558417,
	-29.636131,
	-32.36695,
	-15.536088,
	9.604058,
	28.63583,
	30.462465,
	14.401677,
	-8.31966,
	-23.322582,
	-20.143332,
	-3.2290323,
	14.194936,
	19.752457,
	12.66615,
	2.3620787,
	-1.8976066,
	0.9982482,
	4.4868045,
	1.6978384,
	-6.35166,
	-13.8764305,
	-14.370552,
	-5.772375,
	9.260565,
	21.965069,
	21.90946,
	7.388989,
	-15.017604,
	-32.96273,
	-34.324852,
	-15.072889,
	15.906135,
	41.054108,
	44.900402,
	23.818476,
	-9.590019,
	-35.533764,
	-40.32131,
	-24.745113,
	-0.5224199,
	18.632906,
	23.670383,
	15.551455,
	4.2718973,
	-1.7253747,
	-1.179429,
	0.8958032,
	0.4168465,
	-5.346755,
	-12.88617,
	-15.425676,
	-9.115409,
	3.6483335,
	14.635135,
	14.524587,
	3.7864366,
	-7.6489367,
	-10.744684,
	-5.3550715,
	2.579059,
	7.776786,
	6.7831616,
	0.64107656,
	-7.602022,
	-11.749143,
	-6.810172,
	5.5743227,
	16.742014,
	17.87137,
	6.4149375,
	-12.177473,
	-25.80839,
	-25.393782,
	-8.950111,
	14.343971,
	30.033129,
	29.631594,
	13.684216,
	-8.015286,
	-24.238129,
	-26.9853,
	-15.975739,
	1.9610032,
	16.525848,
	20.099346,
	13.078042,
	1.069541,
	-7.9818172,
	-11.163527,
	-10.865712,
	-9.291611,
	-7.110765,
	-1.3721111,
	8.718294,
	19.507202,
	23.934742,
	15.49859,
	-6.3103933,
	-30.38981,
	-41.752136,
	-29.653894,
	1.8693817,
	35.148228,
	49.09488,
	33.992577,
	-0.7820052,
	-35.00282,
	-47.524826,
	-31.705524,
	1.7508585,
	33.451035,
	44.315704,
	28.925888,
	-2.6437798,
	-29.434982,
	-33.88138,
	-15.733368,
	10.781885,
	26.246422,
	21.180532,
	1.7339766,
	-16.230711,
	-19.984795,
	-9.709598,
	3.8158925,
	9.530277,
	2.9212427,
	-8.662416,
	-13.76534,
	-5.939713,
	10.200792,
	21.778797,
	16.460577,
	-6.300394,
	-29.481358,
	-33.343155,
	-10.539869,
	24.635548,
	45.98911,
	35.363354,
	-1.8836968,
	-39.537304,
	-51.549522,
	-29.32209,
	10.432031,
	39.014484,
	38.992966,
	13.243189,
	-19.24576,
	-34.9393,
	-23.28672,
	3.8008132,
	23.923193,
	22.217676,
	2.2231512,
	-18.7528,
	-23.5334,
	-6.8752804,
	19.759169,
	34.17662,
	21.342564,
	-12.795728,
	-44.66056,
	-50.208473,
	-21.373703,
	25.194334,
	61.11029,
	61.897152,
	25.02256,
	-27.428467,
	-62.124218,
	-57.80118,
	-19.36556,
	26.595013,
	50.236877,
	40.459988,
	7.5496197,
	-22.612461,
	-30.104666,
	-14.278313,
	7.7950053,
	15.91588,
	3.7623403,
	-16.250448,
	-26.378204,
	-16.835573,
	8.036776,
	30.562143,
	34.35702,
	15.448651,
	-12.805811,
	-32.47475,
	-30.69014,
	-9.064087,
	17.988873,
	33.440273,
	28.376535,
	6.086392,
	-19.5731,
	-32.031906,
	-23.448437,
	-0.4801428,
	22.25375,
	32.928978,
	25.956945,
	4.757822,
	-17.062012,
	-26.703363,
	-20.047817,
	-4.354477,
	9.319701,
	14.666899,
	11.361408,
	4.3867273,
	-0.72832024,
	-1.1440688,
	0.096101165,
	-1.5396806,
	-6.6015534,
	-11.132704,
	-8.908474,
	3.242322,
	21.870829,
	35.304188,
	30.681343,
	3.0559397,
	-35.82573,
	-62.08544,
	-54.17864,
	-10.794539,
	45.33246,
	79.675476,
	69.05519,
	17.211456,
	-47.550186,
	-86.24032,
	-75.283035,
	-23.072382,
	37.82027,
	72.80472,
	67.30321,
	31.743423,
	-11.217604,
	-42.472702,
	-51.351215,
	-39.66307,
	-15.054745,
	12.637165,
	34.469894,
	45.01161,
	40.885384,
	20.972954,
	-9.038021,
	-36.606636,
	-50.065548,
	-40.57646,
	-8.791559,
	32.253937,
	61.348736,
	61.130035,
	27.704008,
	-22.61173,
	-63.427986,
	-72.84994,
	-44.55321,
	7.323335,
	55.1034,
	73.12708,
	52.223354,
	4.285201,
	-43.65207,
	-66.7345,
	-54.032074,
	-14.981431,
	28.769203,
	56.6497,
	56.526394,
	30.518873,
	-8.659804,
	-42.58619,
	-54.66807,
	-39.595367,
	-7.9588776,
	24.159351,
	41.87043,
	39.39097,
	21.447397,
	-1.7525803,
	-19.650402,
	-25.782457,
	-19.597055,
	-7.1123495,
	6.0648594,
	15.283846,
	18.278862,
	15.013155,
	7.4474096,
	-2.6945975,
	-13.1093025,
	-20.615934,
	-19.942394,
	-9.916342,
	6.7845297,
	23.399673,
	32.190804,
	27.625051,
	9.477828,
	-15.5589285,
	-35.37086,
	-37.49121,
	-16.886187,
	16.306067,
	41.316113,
	42.54584,
	18.477337,
	-16.141762,
	-41.35665,
	-43.662174,
	-24.895153,
	2.0510526,
	23.164665,
	31.967352,
	29.377296,
	18.97062,
	6.0490074,
	-8.348945,
	-21.951694,
	-28.40328,
	-22.810045,
	-4.757855,
	17.310858,
	31.530243,
	28.403175,
	8.4757,
	-14.080858,
	-24.145092,
	-17.22818,
	-1.3039894,
	11.5613785,
	12.968822,
	6.346698,
	-1.3219529,
	-5.0925026,
	-4.420428,
	-0.22248626,
	5.9569025,
	11.865085,
	14.126859,
	9.785011,
	-0.04778701,
	-10.111845,
	-13.926256,
	-9.562854,
	-0.20153773,
	9.645484,
	15.25309,
	13.700281,
	4.511157,
	-7.3588448,
	-14.461109,
	-11.723076,
	-1.1171577,
	9.408699,
	11.545761,
	5.4617224,
	-2.2545662,
	-5.3416696,
	-1.873801,
	4.72595,
	8.140751,
	6.0856833,
	-0.010602925,
	-5.3289466,
	-4.8461313,
	0.63586223,
	7.117055,
	8.6159935,
	2.7064328,
	-7.1540837,
	-13.389953,
	-9.831162,
	2.502646,
	17.15447,
	23.134928,
	14.673821,
	-6.842539,
	-29.909164,
	-40.092735,
	-28.051403,
	1.7350042,
	31.71979,
	43.91689,
	28.17063,
	-7.5324817,
	-41.905678,
	-53.180622,
	-31.688065,
	11.144976,
	48.284184,
	57.158863,
	33.56774,
	-7.7573066,
	-44.79924,
	-59.027885,
	-43.79088,
	-7.091835,
	31.216322,
	51.81232,
	45.996166,
	18.986565,
	-14.4249935,
	-37.56718,
	-40.406395,
	-23.83878,
	0.37020552,
	18.549088,
	25.955301,
	23.502872,
	15.371155,
	3.8590562,
	-10.989332,
	-27.718231,
	-36.1858,
	-28.911184,
	-5.2324424,
	24.05219,
	41.385254,
	33.330555,
	3.856583,
	-30.088161,
	-46.515156,
	-31.687124,
	7.112663,
	45.9256,
	58.681797,
	36.05614,
	-8.995938,
	-51.01168,
	-63.24865,
	-36.892456,
	11.364058,
	51.45464,
	58.559887,
	30.265352,
	-13.116356,
	-43.95294,
	-44.10679,
	-16.75543,
	18.107506,
	38.903496,
	35.198116,
	13.203288,
	-11.056892,
	-23.215183,
	-18.566439,
	-4.2787437,
	7.803197,
	9.844744,
	2.3362467,
	-6.281348,
	-7.55733,
	0.29252702,
	10.782332,
	15.079638,
	10.769831,
	0.43119785,
	-8.449425,
	-11.546612,
	-7.4913335,
	1.79777,
	11.15039,
	14.2248335,
	8.034628,
	-5.1330585,
	-17.503527,
	-21.142782,
	-12.885771,
	4.340323,
	21.96612,
	28.60479,
	16.459156,
	-7.716136,
	-28.851223,
	-32.61982,
	-14.973235,
	14.120409,
	35.17568,
	33.767277,
	10.834937,
	-17.16586,
	-31.587383,
	-23.68076,
	0.20037341,
	23.30416,
	29.299788,
	14.22465,
	-10.782109,
	-28.260406,
	-26.197897,
	-7.1951094,
	13.184204,
	21.884039,
	15.049659,
	-0.64423454,
	-14.960868,
	-20.04184,
	-13.369144,
	-0.29940522,
	11.7229595,
	15.421183,
	11.577387,
	4.992675,
	0.19760993,
	-4.1172338,
	-9.758944,
	-16.012957,
	-16.600222,
	-6.294271,
	12.984042,
	32.289024,
	40.1573,
	28.054111,
	-1.5055246,
	-35.178196,
	-53.48634,
	-42.227657,
	-3.8551893,
	42.296444,
	69.04778,
	58.892426,
	15.560412,
	-38.014267,
	-71.314575,
	-65.27221,
	-22.690691,
	32.49072,
	67.30769,
	60.335663,
	16.975208,
	-32.225708,
	-54.877274,
	-39.25995,
	-1.3944438,
	30.818462,
	37.26456,
	19.10991,
	-5.0230026,
	-17.31267,
	-12.613522,
	1.0516021,
	9.732152,
	5.2022314,
	-8.502303,
	-16.620611,
	-9.906899,
	7.740124,
	22.515951,
	21.397718,
	1.907145,
	-23.311441,
	-34.693127,
	-22.355183,
	7.3979435,
	35.987022,
	42.937073,
	22.38138,
	-14.223357,
	-46.177288,
	-52.37703,
	-28.417942,
	12.830078,
	47.79121,
	56.12274,
	34.31072,
	-4.8059907,
	-38.611164,
	-50.097973,
	-35.448814,
	-6.549553,
	18.996784,
	30.89691,
	27.471533,
	13.855581,
	-1.2439831,
	-11.795248,
	-16.50408,
	-16.777308,
	-12.96166,
	-4.218363,
	8.1916685,
	18.017887,
	19.731598,
	10.425647,
	-6.8204703,
	-23.626532,
	-30.090591,
	-20.942112,
	0.41399977,
	24.050592,
	37.770416,
	33.64448,
	11.175551,
	-19.673994,
	-43.495438,
	-46.972416,
	-28.008022,
	2.759178,
	29.723177,
	40.757416,
	31.828878,
	9.472774,
	-14.20798,
	-30.760452,
	-34.00762,
	-24.220713,
	-5.3170037,
	16.311878,
	33.107594,
	37.209976,
	26.086283,
	3.2043233,
	-22.6633,
	-39.787315,
	-36.79411,
	-12.270179,
	22.40377,
	47.199265,
	46.36378,
	19.942522,
	-17.718243,
	-44.33884,
	-45.788048,
	-21.959923,
	13.2881,
	37.884197,
	38.26142,
	17.218945,
	-8.781875,
	-24.433702,
	-24.269506,
	-11.774886,
	3.4989579,
	11.062149,
	6.989755,
	-3.3159652,
	-9.911007,
	-5.9561486,
	5.4245973,
	14.897327,
	13.794471,
	1.9918556,
	-12.360488,
	-17.514511,
	-9.985837,
	4.9951744,
	17.696007,
	19.188053,
	8.83494,
	-4.606941,
	-12.233579,
	-11.797554,
	-5.748431,
	0.74258125,
	5.307013,
	8.1409235,
	8.688247,
	5.930029,
	0.8132747,
	-4.5720024,
	-7.284756,
	-7.0538692,
	-4.5481386,
	-0.3442448,
	5.0235586,
	8.908919,
	6.8492002,
	-3.3427668,
	-15.501396,
	-19.35175,
	-9.561045,
	10.773634,
	28.02311,
	28.61641,
	9.805007,
	-18.087103,
	-38.543243,
	-36.276142,
	-10.671575,
	22.503204,
	41.350277,
	32.338394,
	1.0576553,
	-31.999025,
	-45.449673,
	-29.74453,
	5.9739594,
	39.16398,
	47.26519,
	23.595646,
	-17.189486,
	-47.36831,
	-46.67746,
	-16.571613,
	22.801498,
	45.448593,
	39.36623,
	13.485542,
	-12.25136,
	-21.46859,
	-12.742094,
	0.608852,
	2.6366777,
	-9.619221,
	-24.119352,
	-21.915625,
	4.2083044,
	39.94775,
	58.975975,
	40.63017,
	-11.839708,
	-67.269615,
	-88.61527,
	-58.50491,
	7.05261,
	70.52269,
	95.98838,
	70.08857,
	8.340234,
	-53.181778,
	-81.78927,
	-65.33317,
	-18.337006,
	30.811932,
	55.654316,
	47.588715,
	18.451778,
	-12.58433,
	-30.114824,
	-30.407314,
	-19.320122,
	-5.902038,
	4.7409725,
	12.807055,
	19.250738,
	20.92791,
	13.701821,
	-3.1539712,
	-22.579315,
	-32.90551,
	-23.420416,
	2.785747,
	30.965136,
	42.61728,
	27.266527,
	-7.4746346,
	-39.9596,
	-48.793293,
	-28.760765,
	9.718923,
	43.23199,
	49.730072,
	26.837189,
	-9.522244,
	-35.786488,
	-36.333065,
	-14.1203985,
	12.547031,
	25.900318,
	18.779829,
	-2.0417614,
	-21.419533,
	-25.205938,
	-11.784272,
	9.082299,
	23.378008,
	21.310345,
	5.7484293,
	-10.379241,
	-15.53222,
	-8.839609,
	2.4080498,
	8.118145,
	4.60679,
	-2.6841502,
	-6.5382853,
	-5.3059483,
	-1.7687609,
	0.9891817,
	1.8522763,
	1.5078413,
	2.9091766,
	5.5676103,
	5.2944345,
	-1.6037611,
	-9.695883,
	-11.682761,
	-3.3225863,
	11.784307,
	22.954033,
	20.338268,
	2.7343097,
	-20.216812,
	-34.894825,
	-29.324064,
	-5.0991325,
	24.755732,
	42.42772,
	35.80054,
	6.7993474,
	-26.925888,
	-44.61197,
	-34.634037,
	-2.762344,
	31.305561,
	46.629803,
	33.8412,
	1.6780076,
	-29.959007,
	-41.5774,
	-27.371098,
	2.4205446,
	28.884846,
	37.06467,
	22.516653,
	-5.9576945,
	-30.338562,
	-35.737453,
	-20.9515,
	3.6240587,
	23.687145,
	28.685799,
	17.816744,
	-1.5330722,
	-17.676634,
	-21.549139,
	-12.138067,
	3.963091,
	16.33541,
	16.899193,
	7.1550226,
	-5.745438,
	-13.082829,
	-10.45856,
	-2.5221915,
	5.266602,
	6.7086782,
	-0.30678403,
	-9.7567,
	-13.539174,
	-7.749904,
	3.603398,
	15.714295,
	21.173662,
	13.815037,
	-2.2912183,
	-17.1905,
	-23.588644,
	-18.097038,
	-1.6847532,
	16.551254,
	25.629913,
	19.272444,
	0.7866209,
	-18.876455,
	-27.65028,
	-20.138329,
	-0.5079931,
	19.696888,
	27.925732,
	19.04283,
	0.77511024,
	-15.956814,
	-23.211557,
	-16.803741,
	-1.4471182,
	14.55022,
	21.473055,
	16.894945,
	5.392606,
	-6.0781226,
	-13.65553,
	-15.9830475,
	-16.441605,
	-13.021093,
	-3.6245587,
	9.597276,
	22.085588,
	26.145044,
	17.767042,
	-1.4018457,
	-20.810337,
	-27.834152,
	-17.97815,
	0.5037422,
	14.137158,
	14.681675,
	4.6272554,
	-5.4820075,
	-6.4710383,
	1.8532828,
	11.5201845,
]


def doit(verbose = 0):

    print __doc__

    a = np.array(data)
    r = mtanalyze(a - a.mean(),
                  dt = dt,
                  kind = 2,
                  npi = 4,
                  nwin = 7,
                  padby = 0,
                  doplot = 1,
                  verbose = verbose,
                  title = "Adaptive Multi-taper of AR(4)",
                  )

    return r

